/*
 * Copyright (C) 2013 Daniel Wasilew <daniel.wasilew@codeminer.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.codeminer.parts.server.actions;

import org.codehaus.jackson.annotate.JsonCreator;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author Daniel Wasilew <daniel.wasilew@codeminer.org>
 */
public class ActionProperties {

    private String actionName;
    private UUID sessionId;
    private Map<String, String> parameters = new HashMap<>();

    @JsonCreator
    public ActionProperties(Map<String, Object> props) {
        this.actionName = (String) props.remove("actionName");
        String tmpId = (String) props.remove("sessionId");
        if (tmpId != null) {
            this.sessionId = UUID.fromString(tmpId);
        }
        for (Map.Entry<String, Object> entry : props.entrySet()) {
            this.parameters.put(entry.getKey(), (String) entry.getValue());
        }
    }

    public String getParameter(String key) {
        if (this.parameters == null) {
            return null;
        }
        return this.parameters.get(key);
    }

    public Boolean getBooleanParameter(String key) {
        return Boolean.valueOf(getParameter(key));
    }

    public Long getLongParameter(String key) {
        return Long.parseLong(getParameter(key));
    }

    public UUID getUUIdParameter(String key) {
        return UUID.fromString(getParameter(key));
    }

    public String getActionName() {
        return actionName;
    }

    public UUID getSessionId() {
        return sessionId;
    }
}
